<?php

class SlidersController extends Controller
{
	public function actionIndex()
	{
		$model = new Events;
		
		$criteria = new CDbCriteria();
		$criteria->condition = 'featured="Y"';
		$dataProvider=new CActiveDataProvider('Events',
			array(
				'criteria'=>$criteria,
				'sort'=>array(
					'defaultOrder'=>'posteddate DESC',
				),
				'pagination'=>array(
					'pageSize'=>10,
					'pageVar'=>'page',
				),
			)
		);
		$this->render('index', array(
			'dataProvider'=>$dataProvider,
			'model'=>$model
		));
	}
	
	public function actionCreate()
	{
		if (isset($_POST['Events'])) {
			$model = Events::model()->findByPk($_POST['Events']['id']);
			
			if (isset($model)) {
				$model->updateByPk($model->id, array('featured'=>'Y'));
				$this->redirect(array('/Events/sliders/index'));
			}
		}
	}
	
	public function actionDelete($id)
	{
		$model = Events::model()->findByPk($id);
		
		if (isset($model)) {
			$model->updateByPk($id, array('featured'=>'N'));
		}
		if(!isset($_GET['ajax']))
			$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
	}
}